package com.wenhui.schoolyardinfo.square;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qmuiteam.qmui.widget.QMUILoadingView;
import com.qmuiteam.qmui.widget.QMUITopBar;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.wenhui.schoolyardinfo.R;
import com.wenhui.schoolyardinfo.base.BaseMvpFragment;
import com.wenhui.schoolyardinfo.callback.RcvOnFirstSecondThirdViewClickListener;
import com.wenhui.schoolyardinfo.callback.RcvOnFirstSecondViewClickListener;
import com.wenhui.schoolyardinfo.callback.RcvOnItemViewClickListener;
import com.wenhui.schoolyardinfo.customview.CommonPopupWindow;
import com.wenhui.schoolyardinfo.customview.RecyclerViewDivider;
import com.wenhui.schoolyardinfo.firstpage.adapter.BaseRecyclerAdapter;
import com.wenhui.schoolyardinfo.firstpage.bean.BlogBean;
import com.wenhui.schoolyardinfo.firstpage.bean.CommentBean;
import com.wenhui.schoolyardinfo.firstpage.bean.SubcommentsBean;
import com.wenhui.schoolyardinfo.firstpage.holder.SmartViewContentHolder;
import com.wenhui.schoolyardinfo.firstpage.ui.HomePageActivity;
import com.wenhui.schoolyardinfo.firstpage.ui.SearchActivity;
import com.wenhui.schoolyardinfo.login.view.base.IBaseView;
import com.wenhui.schoolyardinfo.manager.InputManager;
import com.wenhui.schoolyardinfo.manager.LogManager;
import com.wenhui.schoolyardinfo.manager.PopupWindowManager;
import com.wenhui.schoolyardinfo.manager.ScreenManager;
import com.wenhui.schoolyardinfo.mine.ui.ShowPicturesActivity;
import com.wenhui.schoolyardinfo.square.adapter.SquareAdapter;
import com.wenhui.schoolyardinfo.square.bean.SquareRecommendBean;
import com.wenhui.schoolyardinfo.square.presenter.SquarePresenterImpl;
import com.wenhui.schoolyardinfo.square.ui.ConcernActivity;
import com.wenhui.schoolyardinfo.square.ui.FmActivity;
import com.wenhui.schoolyardinfo.square.ui.PublicGoodActivity;
import com.wenhui.schoolyardinfo.square.ui.RecommendActivity;
import com.wenhui.schoolyardinfo.square.view.ISquareView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * author    : Urasaki
 * e-mail    : 1164688204@qq.com
 * date      : 2019/6/12B 16:15
 * introduce :
 */

public class SquareFragment extends BaseMvpFragment<IBaseView, SquarePresenterImpl> implements RcvOnItemViewClickListener,
        RcvOnFirstSecondViewClickListener, RcvOnFirstSecondThirdViewClickListener, ISquareView {

    private static final String TAG = "SquareFragment";
    @BindView(R.id.imv_search)
    ImageView imvSearch;
    @BindView(R.id.layout_search)
    RelativeLayout layoutSearch;
    @BindView(R.id.topbar)
    QMUITopBar topbar;
    @BindView(R.id.square_recycler_view)
    RecyclerView squareRecyclerView;
    @BindView(R.id.show_only_square_recycler_view)
    RecyclerView showOnlySquareRecyclerView;
    @BindView(R.id.refresh_layout)
    SmartRefreshLayout refreshLayout;
    @BindView(R.id.edt_input)
    EditText edtInput;
    @BindView(R.id.tev_send)
    TextView tevSend;
    @BindView(R.id.layout_input)
    RelativeLayout layoutInput;
    Unbinder unbinder;
    private QMUILoadingView loadView;

    private List<SquareRecommendBean> squareRecommendBeanList;
    private List<BlogBean> blogBeanList;
    private List<String> sceneryUrlList;
    private List<CommentBean> commentBeanList;
    private List<SubcommentsBean> subcommentsBeanList;
    private SquareAdapter squareAdapter;
    private LinearLayoutManager layoutManager;
    //Popwindow
    private CommonPopupWindow window;
    private RecyclerView moreRecyclerView;
    private RelativeLayout layoutAngleLabelTop;
    private RelativeLayout layoutAngleLabelBottom;
    private BaseRecyclerAdapter<String> baseRecyclerAdapter;
    private List<String> stringList;

    private Map<String, String> bodyParams;
    private boolean isShowOnlySquare;
    private boolean isSubcomment;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_square, container, false);
        unbinder = ButterKnife.bind(this, view);

        initData();
        initViews();
        return view;
    }

    @Override
    protected void initData() {

        squareRecommendBeanList = new ArrayList<>();
        blogBeanList = new ArrayList<>();
        sceneryUrlList = new ArrayList<>();
        subcommentsBeanList = new ArrayList<>();
        commentBeanList = new ArrayList<>();
        squareRecommendBeanList.add(new SquareRecommendBean("https://gss3.bdstatic.com/-Po3dSag_xI4khGkpoWK1HF6" +
                "hhy/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=5b4f6ad1a74bd11310c0bf603bc6cf6a/023b5bb5c9ea15cea5096eabbc003af33b87b2a9.jpg",
                "似水流年", 300, 1000000, true));
        squareRecommendBeanList.add(new SquareRecommendBean("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg",
                "素华流年", 500, 2000000, false));
        squareRecommendBeanList.add(new SquareRecommendBean("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg",
                "冉冉流年", 700, 10000000, false));
        squareRecommendBeanList.add(new SquareRecommendBean("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg",
                "似水流年", 30, 100000, false));
        squareRecommendBeanList.add(new SquareRecommendBean("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg",
                "似水流年", 30, 100000, false));
        sceneryUrlList.add("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg");
        sceneryUrlList.add("https://ws1.sinaimg.cn/large/0065oQSqly1fuh5fsvlqcj30sg10onjk.jpg");
        subcommentsBeanList.add(new SubcommentsBean("卡尔.邓尼茨", "埃尔温.隆美尔", "我的狼群战术"));
        subcommentsBeanList.add(new SubcommentsBean("卡尔.邓尼茨", "埃尔温.隆美尔", "我的狼群战术"));

        commentBeanList.add(new CommentBean("埃尔温.隆美尔", "我的第七装甲师", subcommentsBeanList));
        commentBeanList.add(new CommentBean("埃尔温.隆美尔", "我的第七装甲师", subcommentsBeanList));

        blogBeanList.add(new BlogBean("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", "埃尔温.隆美尔", 10000010101010L,
                "来自清华大学", "人活着的意义，就是活得有价值，可惜很多的人把这种价值看得太浅了，" +
                "认为拥有更多的财富、拥有社会地位、拥有名气就是价值的体现。这种价值是一种虚伪的价值，更经不起时间的考验。" +
                "因为这个世界不缺少物质，钱也只是我们获取物质的手段罢了。我们真正缺少的是一种精神、一种真理、一种新知与美，" +
                "因为这些才能贴近我们的情感，贴近人性，才能让我们感动，才能激发我们潜在的感情与能量。与物质有关的东西，最终是" +
                "会被时间所遗忘的，并会很快地被遗忘。即使被历史留下了，也是因为一种精神而被留下的。这个世界不缺乏物质，更因为" +
                "很多的人在内心深处，真正想要的并不是金钱利益，而是一种灵魂的归属，可是多数人从来就没有真正地了解过真实的自己，" +
                "只是把虚假的自己关在了一个笼子里痛苦，把真实的自己放在了笼子外流浪。我们应该更深层次地去发现自己，做个自己想要的那个自己。", sceneryUrlList,
                "军事家", 1000, 1000, 1000, 1000, commentBeanList));
        blogBeanList.add(new BlogBean("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", "埃尔温.隆美尔", 10000010101010L,
                "来自清华大学", "人活着的意义，就是活得有价值，可惜很多的人把这种价值看得太浅了，" +
                "认为拥有更多的财富、拥有社会地位、拥有名气就是价值的体现。这种价值是一种虚伪的价值，更经不起时间的考验。" +
                "因为这个世界不缺少物质，钱也只是我们获取物质的手段罢了。我们真正缺少的是一种精神、一种真理、一种新知与美，" +
                "因为这些才能贴近我们的情感，贴近人性，才能让我们感动，才能激发我们潜在的感情与能量。与物质有关的东西，最终是" +
                "会被时间所遗忘的，并会很快地被遗忘。即使被历史留下了，也是因为一种精神而被留下的。这个世界不缺乏物质，更因为" +
                "很多的人在内心深处，真正想要的并不是金钱利益，而是一种灵魂的归属，可是多数人从来就没有真正地了解过真实的自己，" +
                "只是把虚假的自己关在了一个笼子里痛苦，把真实的自己放在了笼子外流浪。我们应该更深层次地去发现自己，做个自己想要的那个自己。", sceneryUrlList,
                "军事家", 1000, 1000, 1000, 1000, commentBeanList));
        blogBeanList.add(new BlogBean("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", "埃尔温.隆美尔", 10000010101010L,
                "来自清华大学", "人活着的意义，就是活得有价值，可惜很多的人把这种价值看得太浅了，" +
                "认为拥有更多的财富、拥有社会地位、拥有名气就是价值的体现。这种价值是一种虚伪的价值，更经不起时间的考验。" +
                "因为这个世界不缺少物质，钱也只是我们获取物质的手段罢了。我们真正缺少的是一种精神、一种真理、一种新知与美，" +
                "因为这些才能贴近我们的情感，贴近人性，才能让我们感动，才能激发我们潜在的感情与能量。与物质有关的东西，最终是" +
                "会被时间所遗忘的，并会很快地被遗忘。即使被历史留下了，也是因为一种精神而被留下的。这个世界不缺乏物质，更因为" +
                "很多的人在内心深处，真正想要的并不是金钱利益，而是一种灵魂的归属，可是多数人从来就没有真正地了解过真实的自己，" +
                "只是把虚假的自己关在了一个笼子里痛苦，把真实的自己放在了笼子外流浪。我们应该更深层次地去发现自己，做个自己想要的那个自己。", sceneryUrlList,
                "军事家", 1000, 1000, 1000, 1000, commentBeanList));
        blogBeanList.add(new BlogBean("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", "埃尔温.隆美尔", 10000010101010L,
                "来自清华大学", "人活着的意义，就是活得有价值，可惜很多的人把这种价值看得太浅了，" +
                "认为拥有更多的财富、拥有社会地位、拥有名气就是价值的体现。这种价值是一种虚伪的价值，更经不起时间的考验。" +
                "因为这个世界不缺少物质，钱也只是我们获取物质的手段罢了。我们真正缺少的是一种精神、一种真理、一种新知与美，" +
                "因为这些才能贴近我们的情感，贴近人性，才能让我们感动，才能激发我们潜在的感情与能量。与物质有关的东西，最终是" +
                "会被时间所遗忘的，并会很快地被遗忘。即使被历史留下了，也是因为一种精神而被留下的。这个世界不缺乏物质，更因为" +
                "很多的人在内心深处，真正想要的并不是金钱利益，而是一种灵魂的归属，可是多数人从来就没有真正地了解过真实的自己，" +
                "只是把虚假的自己关在了一个笼子里痛苦，把真实的自己放在了笼子外流浪。我们应该更深层次地去发现自己，做个自己想要的那个自己。", sceneryUrlList,
                "军事家", 1000, 1000, 1000, 1000, commentBeanList));
        blogBeanList.add(new BlogBean("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", "埃尔温.隆美尔", 10000010101010L,
                "来自清华大学", "人活着的意义，就是活得有价值，可惜很多的人把这种价值看得太浅了，" +
                "认为拥有更多的财富、拥有社会地位、拥有名气就是价值的体现。这种价值是一种虚伪的价值，更经不起时间的考验。" +
                "因为这个世界不缺少物质，钱也只是我们获取物质的手段罢了。我们真正缺少的是一种精神、一种真理、一种新知与美，" +
                "因为这些才能贴近我们的情感，贴近人性，才能让我们感动，才能激发我们潜在的感情与能量。与物质有关的东西，最终是" +
                "会被时间所遗忘的，并会很快地被遗忘。即使被历史留下了，也是因为一种精神而被留下的。这个世界不缺乏物质，更因为" +
                "很多的人在内心深处，真正想要的并不是金钱利益，而是一种灵魂的归属，可是多数人从来就没有真正地了解过真实的自己，" +
                "只是把虚假的自己关在了一个笼子里痛苦，把真实的自己放在了笼子外流浪。我们应该更深层次地去发现自己，做个自己想要的那个自己。", sceneryUrlList,
                "军事家", 1000, 1000, 1000, 1000, commentBeanList));

        stringList = new ArrayList<>();
        stringList.add("关注");
        stringList.add("私信");
        stringList.add("收藏");
        stringList.add("举报");

        loadView = new QMUILoadingView(getActivity());
        loadView.setVisibility(View.GONE);
        loadView.setSize(120);

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
        layoutParams.gravity = Gravity.CENTER;
        getActivity().addContentView(loadView, layoutParams);

        bodyParams = new HashMap<>();
        bodyParams.put("", "");
        bodyParams.put("", "");
        presenter = initPresenter();
//        presenter.getSquareData(bodyParams);
        isShowOnlySquare = false;
    }

    @Override
    protected void initViews() {
        setTopBar(topbar);
        topbar.removeAllLeftViews();

        initAdapter(false);
        initPopupWindow();

        squareRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);

                final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) squareRecyclerView.getLayoutManager();

                int visibleItemCount = linearLayoutManager.getChildCount(); //子数
                int totalItemCount = linearLayoutManager.getItemCount(); // item总数
                //当前屏幕 首个 可见的 Item 的position
                int firstVisiblePosition = linearLayoutManager.findFirstVisibleItemPosition();
                LogManager.i(TAG, "当前屏幕 可见的 Item 个数:" + visibleItemCount + ",Item总共的个:" + totalItemCount + ",当前屏幕 首个 可见的 Item 的position" + firstVisiblePosition);

                if (!squareAdapter.isShowOnlySquare()) {//如果不是只展示广场数据
                    if (firstVisiblePosition < 2 && isShowOnlySquare) {
                        initAdapter(true);
                    }
                    if (firstVisiblePosition >= 2) {
                        isShowOnlySquare = true;
                    }
                }
            }
        });

    }

    @Override
    public SquarePresenterImpl initPresenter() {
        return new SquarePresenterImpl(getActivity(), this);
    }

    private void initAdapter(boolean isShowOnlySquare) {
        if (!isShowOnlySquare) {
            layoutManager = new LinearLayoutManager(getActivity());
            layoutManager.setOrientation(OrientationHelper.VERTICAL);
            squareRecyclerView.setVisibility(View.VISIBLE);
            showOnlySquareRecyclerView.setVisibility(View.GONE);
            squareRecyclerView.setLayoutManager(layoutManager);
            squareRecyclerView.setItemAnimator(new DefaultItemAnimator());

            squareAdapter = new SquareAdapter(getActivity());
            squareRecyclerView.setAdapter(squareAdapter);
            squareAdapter.setRcvOnItemViewClickListener(this);
            squareAdapter.setRcvOnFirstSecondViewClickListener(this);
            squareAdapter.setRcvOnFirstSecondThirdViewClickListener(this);

            refreshLayout.setOnRefreshListener(new OnRefreshListener() {
                @Override
                public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                    squareAdapter.clearData();
                    squareAdapter.addAllData(squareRecommendBeanList, blogBeanList);
                    refreshLayout.finishRefresh();
                }
            });
            refreshLayout.autoRefresh();
            refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
                @Override
                public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                    blogBeanList.add(new BlogBean("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", "埃里希·冯·曼施坦因", 10000010101010L,
                            "来自曼切斯特大学", "旅行那就是一种随意自然漫无目的的放逐自己，把身心和自然相融，没有具体归期，期间还可以发生很多意想不到的事情，浪漫而浪荡，" +
                            "不管是什么事情，最终都可以包装成人生的丰富经历呈现在人们面前。", sceneryUrlList,
                            "军事家", 1000, 1000, 1000, 1000, commentBeanList));
                    blogBeanList.add(new BlogBean("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", "埃里希·冯·曼施坦因", 10000010101010L,
                            "来自谢菲尔德大学", "淡然的心不计得失，懂得宽容，自然赢得一片宁静。宁静幸福的生活，要用宁静的心来换取。", sceneryUrlList,
                            "军事家", 1000, 1000, 1000, 1000, commentBeanList));

                    squareAdapter.clearData();
                    squareAdapter.addAllData(squareRecommendBeanList, blogBeanList);
                    refreshLayout.finishLoadMore(1000);
                }
            });
        } else {
            layoutManager = new LinearLayoutManager(getActivity());
            layoutManager.setOrientation(OrientationHelper.VERTICAL);
            showOnlySquareRecyclerView.setVisibility(View.VISIBLE);
            squareRecyclerView.setVisibility(View.GONE);
            showOnlySquareRecyclerView.setLayoutManager(layoutManager);
            showOnlySquareRecyclerView.setItemAnimator(new DefaultItemAnimator());

            squareAdapter = new SquareAdapter(getActivity());
            showOnlySquareRecyclerView.setAdapter(squareAdapter);
            squareAdapter.setRcvOnItemViewClickListener(this);
            squareAdapter.setRcvOnFirstSecondViewClickListener(this);
            squareAdapter.setRcvOnFirstSecondThirdViewClickListener(this);
            squareAdapter.clearData();
            squareAdapter.addAllData(true, blogBeanList);
            refreshLayout.setOnRefreshListener(new OnRefreshListener() {
                @Override
                public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                    squareAdapter.clearData();
                    squareAdapter.addAllData(true, blogBeanList);
                    refreshLayout.finishRefresh();
                }
            });
            refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
                @Override
                public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                    blogBeanList.add(new BlogBean("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", "埃里希·冯·曼施坦因", 1000010101010L,
                            "来自慕尼黑大学", "旅行那就是一种随意自然漫无目的的放逐自己，把身心和自然相融，没有具体归期，期间还可以发生很多意想不到的事情，浪漫而浪荡，" +
                            "不管是什么事情，最终都可以包装成人生的丰富经历呈现在人们面前。", sceneryUrlList,
                            "军事家", 1000, 1000, 1000, 1000, commentBeanList));
                    blogBeanList.add(new BlogBean("http://ww1.sinaimg.cn/large/0065oQSqly1fsfq1k9cb5j30sg0y7q61.jpg", "埃里希·冯·曼施坦因", 1000010101010L,
                            "来自伦敦大学国王学院", "淡然的心不计得失，懂得宽容，自然赢得一片宁静。宁静幸福的生活，要用宁静的心来换取。", sceneryUrlList,
                            "军事家", 1000, 1000, 1000, 1000, commentBeanList));

                    squareAdapter.clearData();
                    squareAdapter.addAllData(squareRecommendBeanList, blogBeanList);
                    refreshLayout.finishLoadMore(1000);
                }
            });
        }
    }

    private void initPopupWindow() {
        // create popup window
        window = new CommonPopupWindow(getActivity(), R.layout.popup_window_recommend, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) {
            @Override
            protected void initViews() {
                View view = getContentView();
                layoutManager = new LinearLayoutManager(getActivity());
                layoutManager.setOrientation(OrientationHelper.VERTICAL);

                moreRecyclerView = view.findViewById(R.id.more_recycler_view);
                layoutAngleLabelTop = view.findViewById(R.id.layout_angle_label_top);
                layoutAngleLabelBottom = view.findViewById(R.id.layout_angle_label_bottom);
                moreRecyclerView.setItemAnimator(new DefaultItemAnimator());
                moreRecyclerView.setLayoutManager(layoutManager);
                moreRecyclerView.addItemDecoration(new RecyclerViewDivider(
                        getActivity(),
                        LinearLayoutManager.VERTICAL,
                        ScreenManager.dipTopx(getActivity(), 1),
                        getResources().getColor(R.color.colorGrayB)));
                baseRecyclerAdapter = new BaseRecyclerAdapter<String>(R.layout.item_popup_window_recommend, 1) {
                    @Override
                    protected void onBindViewHolder(RecyclerView.ViewHolder holder, String model, int position) {
                        if (holder instanceof SmartViewContentHolder) {
                            SmartViewContentHolder smartViewContentHolder = (SmartViewContentHolder) holder;
                            smartViewContentHolder.text(R.id.tev_concern, model);

                            View viewConcern = smartViewContentHolder.getView(R.id.view_concern);
                            if (position == stringList.size() - 1) {
                                viewConcern.setVisibility(View.GONE);
                            }
                        }
                    }
                };

                moreRecyclerView.setAdapter(baseRecyclerAdapter);

                baseRecyclerAdapter.clearData();
                baseRecyclerAdapter.addAllData(stringList);
            }

            @Override
            protected void initEvent() {
                baseRecyclerAdapter.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        switch (position) {
                            case 0:
                                showToast("点击了concern");
                                break;
                            case 1:
                                showToast("点击了privateLetter");
                                break;
                            case 2:
                                showToast("点击了collect");
                                break;
                            case 3:
                                showToast("点击了report");
                                break;
                        }
//                        window.getPopupWindow().dismiss();
                    }
                });
            }

            @Override
            protected void initWindow() {
                super.initWindow();
                PopupWindow instance = getPopupWindow();
                instance.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    @Override
                    public void onDismiss() {
                        WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes();
                        lp.alpha = 1.0f;
                        getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                        getActivity().getWindow().setAttributes(lp);
                    }
                });
            }
        };
    }

    private void showPopupWindow(View anchorView) {
        PopupWindow mPopupWindow = window.getPopupWindow();
        mPopupWindow.setAnimationStyle(R.style.animTranslate);
        // 如果不设置PopupWindow的背景，有些版本就会出现一个问题：无论是点击外部区域还是Back键都无法dismiss弹框
        mPopupWindow.setBackgroundDrawable(new ColorDrawable());
        // 设置点击窗口外边窗口消失
        mPopupWindow.setOutsideTouchable(true);
        // 设置此参数获得焦点，否则无法点击
        mPopupWindow.setFocusable(true);
        // 设置好参数之后再show
        int windowPos[] = PopupWindowManager.calculatePopWindowPos(anchorView, window.getContentView());
        int xOff = 20; // 可以自己调整偏移
        windowPos[0] -= xOff;

        //是否需要向上弹出/向下弹出显示
        boolean isNeedShowUp = PopupWindowManager.isNeedShowUp(anchorView, window.getContentView());
        if (isNeedShowUp) {
            layoutAngleLabelTop.setVisibility(View.GONE);
            layoutAngleLabelBottom.setVisibility(View.VISIBLE);
        } else {
            layoutAngleLabelTop.setVisibility(View.VISIBLE);
            layoutAngleLabelBottom.setVisibility(View.GONE);
        }
        // 设置popupWindow的显示位置
        mPopupWindow.showAtLocation(anchorView, Gravity.TOP | Gravity.START, windowPos[0], windowPos[1]);

        WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes();
        lp.alpha = 0.3f;
        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        getActivity().getWindow().setAttributes(lp);
    }

    private void startActivity(int currentPosition, List<String> sceneryUrlList) {
        Intent intent = new Intent(getActivity(), ShowPicturesActivity.class);
        Bundle bundle = new Bundle();
        ArrayList<String> photoUrlList = new ArrayList<>();
        photoUrlList.addAll(sceneryUrlList);
        bundle.putInt("currentPosition", currentPosition);
        bundle.putStringArrayList("photoUrlList", photoUrlList);
        intent.putExtras(bundle);
        startActivity(intent);
        getActivity().overridePendingTransition(R.anim.translate_out, R.anim.translate_in);
    }

    @Override
    public void showLoading() {
        loadView.setVisibility(View.VISIBLE);
        loadView.start();
    }

    @Override
    public void hideLoading() {
        loadView.stop();
        loadView.setVisibility(View.GONE);
    }

    @Override
    public void getSquareDataSuccess(String success) {
Log.e(TAG,success);
    }

    @Override
    public void getSquareDataError(String error) {
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();

        hideLoading();
    }

    @Override
    public void onItemClickListener(int position, View view) {
        switch (view.getId()) {
            case R.id.layout_recommend:
                showToast(position + "*****点击了layout_recommend");
                startActivity(RecommendActivity.class);
                break;
            case R.id.layout_micro_public_good:
                showToast(position + "*****点击了layout_micro_public_good");
                startActivity(PublicGoodActivity.class);
                break;
            case R.id.layout_f_m:
//                showToast(position + "*****点击了layout_f_m");
                startActivity(FmActivity.class);
                break;
            case R.id.layout_activity:
                showToast(position + "*****点击了layout_activity");
                break;
            case R.id.layout_concern:
                showToast(position + "*****点击了layout_concern");
                startActivity(ConcernActivity.class);
                break;
            case R.id.layout_notes:
                showToast(position + "*****点击了layout_notes");
                break;
            case R.id.imv_head_portrait:
                showToast(position + "*****点击了imv_head_portrait");
                startActivity(HomePageActivity.class);
                break;
            case R.id.layout_more:
                showPopupWindow(view);
                break;
            case R.id.layout_fire:
                showToast(position + "*****点击了layout_fire");
                break;
            case R.id.layout_feeling:
                showToast(position + "*****点击了layout_feeling");
                break;
            case R.id.layout_comment:
                showToast(position + "*****点击了layout_comment");
                break;
            case R.id.layout_shared:
                showToast(position + "*****点击了layout_shared");
                break;
            case R.id.layout_spread:
                showToast(position + "*****点击了layout_spread");
                commentBeanList.add(new CommentBean("埃尔温.隆美尔", "我的第七装甲师", subcommentsBeanList));
                commentBeanList.add(new CommentBean("埃尔温.隆美尔", "我的第七装甲师", subcommentsBeanList));
                commentBeanList.add(new CommentBean("埃尔温.隆美尔", "我的第七装甲师", subcommentsBeanList));
                commentBeanList.add(new CommentBean("埃尔温.隆美尔", "我的第七装甲师", subcommentsBeanList));
                commentBeanList.add(new CommentBean("埃尔温.隆美尔", "我的第七装甲师", subcommentsBeanList));

                squareAdapter.clearData();
                squareAdapter.addAllData(squareRecommendBeanList, blogBeanList);
                break;
            case R.id.imv_scenery_i_a:
                startActivity(0, blogBeanList.get(position).getSceneryUrlList());
                break;
            case R.id.imv_scenery_ii_a:
                startActivity(0, blogBeanList.get(position).getSceneryUrlList());
                break;
            case R.id.imv_scenery_ii_b:
                startActivity(1, blogBeanList.get(position).getSceneryUrlList());
                break;
            case R.id.imv_scenery_iii_a:
                startActivity(0, blogBeanList.get(position).getSceneryUrlList());
                break;
            case R.id.imv_scenery_iii_b:
                startActivity(1, blogBeanList.get(position).getSceneryUrlList());
                break;
            case R.id.imv_scenery_iii_c:
                startActivity(2, blogBeanList.get(position).getSceneryUrlList());
                break;
            default:
                break;
        }
    }

    @Override
    public void onItemItemClickListener(int position, int position2, View view) {
        switch (view.getId()) {
            case R.id.layout_close:
                showToast("position:" + position
                        + "***position2:" + position2 + "*****点击了layout_close");
                break;
            case R.id.layout_concern_add:
                showToast("position:" + position
                        + "***position2:" + position2 + "*****点击了layout_concern_add");
                break;
            case R.id.tev_name:
                showToast("position:" + position
                        + "***position2:" + position2 + "*****点击了tev_name");
                LogManager.i(TAG, "position:" + position
                        + "***position2:" + position2 + "*****点击了tev_name");
                break;
            case R.id.tev_comment:
                showToast("position:" + position
                        + "***position2:" + position2 + "*****点击了tev_comment");
                LogManager.i(TAG, "position:" + position
                        + "***position2:" + position2 + "*****点击了tev_comment");
                layoutInput.setVisibility(View.VISIBLE);
                isSubcomment = false;
                InputManager.showInput(edtInput);
                break;
            case R.id.layout_spread:
                showToast("position:" + position
                        + "***position2:" + position2 + "*****点击了layout_spread");
                LogManager.i(TAG, "position:" + position
                        + "***position2:" + position2 + "*****点击了layout_spread");
                subcommentsBeanList.add(new SubcommentsBean("卡尔.邓尼茨", "埃尔温.隆美尔", "我的狼群战术"));
                subcommentsBeanList.add(new SubcommentsBean("卡尔.邓尼茨", "埃尔温.隆美尔", "我的狼群战术"));
                subcommentsBeanList.add(new SubcommentsBean("卡尔.邓尼茨", "埃尔温.隆美尔", "我的狼群战术"));
                subcommentsBeanList.add(new SubcommentsBean("卡尔.邓尼茨", "埃尔温.隆美尔", "我的狼群战术"));
                subcommentsBeanList.add(new SubcommentsBean("卡尔.邓尼茨", "埃尔温.隆美尔", "我的狼群战术"));

                squareAdapter.clearData();
                squareAdapter.addAllData(squareRecommendBeanList, blogBeanList);
                break;
            default:
                break;
        }
    }

    @Override
    public void onItemItemItemClickListener(int position, int position2, int position3, View view) {
        switch (view.getId()) {
            case R.id.tev_first_name:
                showToast("position:" + position
                        + "***position2:" + position2
                        + "***position3:" + position3 + "*****点击了tev_first_name");
                LogManager.i(TAG, "position:" + position
                        + "***position2:" + position2
                        + "***position3:" + position3 + "*****点击了tev_first_name");
                break;
            case R.id.tev_second_name:
                showToast("position:" + position
                        + "***position2:" + position2
                        + "***position3:" + position3 + "*****点击了tev_second_name");
                LogManager.i(TAG, "position:" + position
                        + "***position2:" + position2
                        + "***position3:" + position3 + "*****点击了tev_second_name");
                break;
            case R.id.tev_subcomment:
                showToast("position:" + position
                        + "***position2:" + position2
                        + "***position3:" + position3 + "*****点击了tev_subcomment");
                LogManager.i(TAG, "position:" + position
                        + "***position2:" + position2
                        + "***position3:" + position3 + "*****点击了tev_subcomment");
                layoutInput.setVisibility(View.VISIBLE);
                isSubcomment = true;
                InputManager.showInput(edtInput);
                break;
            default:
                break;
        }
    }

    @OnClick({R.id.layout_search, R.id.tev_send})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.layout_search:
                startActivity(SearchActivity.class);
                break;
            case R.id.tev_send:
                LogManager.i(TAG, "tev_send");
                String sendStr = edtInput.getText().toString();
                if (sendStr != null && !"".equals(sendStr)) {
                    if (isSubcomment) {
                        subcommentsBeanList.add(new SubcommentsBean("卡尔.邓尼茨", "埃尔温.隆美尔", "我的狼群战术"));
                        squareAdapter.clearData();
                        if (isShowOnlySquare) {
                            squareAdapter.addAllData(true, blogBeanList);
                        } else {
                            squareAdapter.addAllData(squareRecommendBeanList, blogBeanList);
                        }
                    } else {
                        commentBeanList.add(new CommentBean("卡尔.邓尼茨", "我的第七装甲师", subcommentsBeanList));
                        squareAdapter.clearData();
                        if (isShowOnlySquare) {
                            squareAdapter.addAllData(true, blogBeanList);
                        } else {
                            squareAdapter.addAllData(squareRecommendBeanList, blogBeanList);
                        }
                    }
                    layoutInput.setVisibility(View.GONE);
                }
                break;
        }
    }
}
